package com.jxzyk.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;

import com.core.ui.bar.widget.MenuItem;
import com.jxzyk.R;

/**
 * 
 * 
 * 
 * @Description: TODO(FootBar样式)
 * 
 * @author gufei 562401002@qq.com
 * 
 * @date 2015年3月18日 上午10:58:28
 */
public class FootItem extends MenuItem {

	private Context mContext;
	private ImageView imageView;
	private TextView textView;
	private Drawable[] icons;
	private int[] colors;
	private String TAG = this.getClass().getName();

	public FootItem(Context context) {
		super(context);
		init(context);
	}

	public FootItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public FootItem(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	private void init(Context context) {
		this.mContext = context;
		LayoutInflater.from(context).inflate(R.layout.common_footbar, this);
		imageView = (ImageView) findViewById(R.id.common_footbar_img);
		textView = (TextView) findViewById(R.id.common_footbar_tv);
	}

	public void setColor(int[] colors) {
		this.colors = colors;
	}

	public void setTitle(String title) {
		textView.setText(title);
	}

	public void setTitle(int resId) {
		textView.setText(resId);
	}

	public Drawable[] getIcons() {
		return icons;
	}

	/*********** 第一张为未选中，第二张为选中 *************/
	public void setIcons(int[] resIds) {
		if (resIds.length > 0) {
			imageView.setImageDrawable(mContext.getResources().getDrawable(
					resIds[0]));
			this.icons = new Drawable[resIds.length];
			for (int i = 0; i < resIds.length; i++) {
				this.icons[i] = mContext.getResources().getDrawable(resIds[i]);
			}
		}
	}

	/*********** 选中 *************/
	public void onClick(int index) {
		Log.d(TAG, "onClick//" + index);
		if (icons.length > 1) {
			imageView.setImageDrawable(icons[1]);
		}
		if (colors.length > 1) {
			textView.setTextColor(getResources().getColor(colors[0]));
		}
	}

	/*********** 未选中 *************/
	public void onUnClick(int index) {
		Log.d(TAG, "onUnClick//" + index);
		if (icons.length > 1) {
			imageView.setImageDrawable(icons[0]);
		}
		if (colors.length > 1) {
			textView.setTextColor(getResources().getColor(colors[1]));
		}
	}
}
